/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package triploa;
import java.util.Vector;
import org.kxml2.io.*;
import org.kxml2.kdom.*;
import org.xmlpull.v1.*;
import java.io.*;
/**
 *
 * @author User
 */
public class SearchResult {
    private String searchID;
    private Vector list;
    private static final String RESULT_TAG="Payload";
    private SearchResult(){}
    public SearchResult(String id,Vector v)
    {
        list=v;
        searchID=id;
    }
    public Vector getList()
    {
        return list;
    }
    public String getID()
    {
        return searchID;
    }
    /**
 * call for getting a new instance of this class from xml
 * @param p Parser
 * @return a new instance of FeedBack
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
    public static SearchResult create(KXmlParser p)throws XmlPullParserException, IOException 
    {
        SearchResult s=new SearchResult();
        s.update(p);
        return s;
    }
    /**
 * Update this object class from xml parser
 * @param p Parser
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
    public void update(KXmlParser p) throws XmlPullParserException, IOException {
        boolean exit = false, result=false;
        int token = -1;
        list=new Vector();
        while (!exit) {
            token = p.next();
            switch (token) {
                case KXmlParser.START_DOCUMENT:
                    break;
                case KXmlParser.END_DOCUMENT:
                    exit = true;  //exit form while
                    break;
                case KXmlParser.START_TAG:
                    System.out.println(p.getName());
                    if (p.getName().equals(this.RESULT_TAG)) {
                        result = true;
                    }
                    if (result) {
                        
                        System.out.println("Inizio parse Travel");
                        Travel app=Travel.create(p);;
                        while(app!=null){ //parse travels
                            list.addElement(app);
                            app=Travel.create(p);
                        }
                        exit=true;
                    }
                    break;
                case KXmlParser.END_TAG:
                    if (result) {
                        if (p.getName().equals(RESULT_TAG)) {
                            result = false;
                            exit = true;
                            break;
                        }
                    }
                    break;
                case KXmlParser.TEXT:
                    break;
            }
        }
    }
}
